<?php 
$show_validator = true;
include TMPL_PATH.'public/header.phtml';
?>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/jscal2.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/border-radius.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/win2k.css"/>
<script type="text/javascript" src="/statics/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/statics/js/calendar/lang/zh-cn.js"></script>
<script type="text/javascript">
<!--
	$(function(){
	$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
 	$("#name").formValidator({onshow:"请输入广告名称",onfocus:"请输入广告名称"}).inputValidator({min:1,onerror:"请输入广告名称"}).inputValidator({min:1,onerror:"请输入广告名称"});
 	$("#position_id").formValidator({onshow:"请选择广告位",onfocus:"请选择广告位",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"请选择广告位"});
// 	$("#link_url").formValidator({onshow:"请输入链接地址",onfocus:"请输入链接地址"}).inputValidator({min:1,onerror:"请输入链接地址"}).regexValidator({regexp:"^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&]*([^<>])*$",onerror:"格式应该为 http://www.cjli.org/"})

	})
//-->
</script>
<style>
.table_form label {
    margin-left: 10px;
    padding: 7px 0 0;
}
</style>
<div class="subnav">
    <div class="content-menu ib-a blue line-x">
        <a href="<?php echo U('adv/adv_list')?>"><em>广告列表</em></a><span>|</span>
        <a href='javascript:;' class="on">编辑广告</a>
    </div>
</div>
<div class="pad_10">
<form action="__SELF__" method="post" name="myform" id="myform" enctype="multipart/form-data">
<table cellpadding="2" cellspacing="1" class="table_form" width="100%">
	<tr>
		<th width="100">名称：</th>
		<td><input type="text" name="name" id="name" size="30" class="input-text" value="<?php echo $adv['name'];?>"></td>
	</tr>
	<tr>
					<th>广告图片：</th>
					<td>
					<input type="hidden" checked="checked" value="1" name="ad_type">
					<input type="file" class="file" name="img">
					<!--	<label class="attr"><input type="radio" <?php if($adv['ad_type']==1) echo 'checked="checked"';?> value="1" name="ad_type">图片</label>
						<label class="attr"><input type="radio" value="2" name="ad_type" <?php if($adv['ad_type']==2) echo 'checked="checked"';?>>flash</label>
						<label class="attr"><input type="radio" value="3" name="ad_type" <?php if($adv['ad_type']==3) echo 'checked="checked"';?>>文字</label>
						<label class="attr"><input type="radio" value="4" name="ad_type" <?php if($adv['ad_type']==4) echo 'checked="checked"';?>>代码</label>
						<div id="ad_box">
							<div style="display: none;">
								<input type="file" class="file" name="img" /><br />
							</div>
							<div style="display: none;">
								<input type="file" class="file" name="flash" /><br />
							</div>
							<div style="display: none;">
								<textarea name="text" style="width:50%;height:50px" class="input-text"><?php if($adv['ad_type']==3) echo $adv['content'];?></textarea>
							</div>
							<div style="display: block;">
								<textarea name="code" style="width:50%;height:50px" class="input-text"><?php if($adv['ad_type']==4) echo $adv['content'];?></textarea>
							</div> 
						</div>-->
					</td>
				</tr>
	<tr>
		<th>广告位：</th>
		<td><select name="position_id" id="position_id">
							<option value="">请选择</option>
							<?php 
							if($positionList && is_array($positionList)):
								foreach ($positionList as $position):
							?>
														<option value="<?php echo $position['id'];?>" <?php if($adv['position_id']==$position['id']) echo 'selected';?>><?php echo $position['name'];?></option>
							<?php 
								endforeach;
							endif;
							?>
													</select></td>
	</tr>
	<tr>
		<th>链接地址：</th>
		<td><input type="text" name="link" id="link_url" size="30" value="<?php echo $adv['link'];?>" class="input-text"></td>
	</tr>
	<tr class="hidden">
	  <th>排序：</th>
	  <td><input type="text" name="listorder" class="input-text" size="5" value="<?php echo $adv['listorder'];?>"/></td>
	</tr>
	<tr class="hidden">
		<th>宽×高：</th>
		<td><input type="text" name="width" size="5" value="<?php echo $adv['width'];?>" class="input-text"> x <input type="text" name="height" size="5" value="<?php echo $adv['height'];?>" class="input-text"> *广告位在页面中所占宽高，如果为0则为不限制</td>
	</tr>
	<tr class="hidden">
		<th>开始和结束时间：</th>
		<td> <input type="text" class="input-text" value="<?php echo $adv['start_time'];?>" name="start_time" id="start_time">&nbsp;&nbsp;&nbsp;
				<script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "start_time",
		    trigger    : "start_time",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
				～  <input type="text" class="input-text" value="<?php echo $adv['end_time'];?>" name="end_time" id="end_time">
				<script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "end_time",
		    trigger    : "end_time",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script><div class="infoShow">广告展示的开始时间和结束时间</div></td>
	</tr>
	<tr>
		<th>图片描述：</th>
		<td><input name="description" class="input-text" size="50" value="<?php echo $adv['description'];?>"><div class="infoShow">鼠标放到图片上的提示文字</div></td>
	</tr>
	<tr>
		<th>广告样式：</th>
		<td><input name="style" class="input-text" size="50" value="<?php echo $adv['style'];?>"><div class="infoShow">首页广告背景样式</div></td>
	</tr>
</table>
<div class="bk15"></div>
		<input name="content" type="hidden" value="<?php echo $adv['content'];?>" />
    <input name="dosubmit" type="submit" class="button" value="提交" id="dosubmit" />
</form>
</div>
<div class="bk15"></div>
<div>
	<img src="<?php echo $adv['content'] ?>" width="300" />
</div>
</body>
<script type="text/javascript">
//单选按钮点击绑定
$('input:radio[name="ad_type"]').each(
	function(i)
	{
		$(this).click
		(
			function(){showType(i);}
		);
	}
);

//广告type 控件的show,hide切换
function showType(indexVal)
{
	$('#ad_box>div').hide();
	$('#ad_box>div:eq('+indexVal+')').show();
}

//预定义type数据
function defaultShowType()
{
	var checkedVal  = "<?php echo $adv['ad_type'];?>";
	<?php if($adv['ad_type'] != 4):?>
	var checkedData = "<?php echo addslashes($adv['content']);?>";
	<?php endif;?>
		var typeHTML    = '';

		var width = <?php echo($adv['width']!=0) ? '" width='.$adv['width'].' "':"''"?>;
		var height = <?php echo($adv['height']!=0) ? '" height='.$adv['height'].' "':"''"?>;

		//如果有数据
		if(checkedData)
		{
			switch(checkedVal)
			{
				case "1":
				var typeHTML = '<img src="'+checkedData+'" '+width+height+' />';
				$('#ad_box>div:eq('+(checkedVal-1)+')').html($('#ad_box>div:eq('+(checkedVal-1)+')').html()+typeHTML);
				break;

				case "2":
				var typeHTML = '<embed src="'+checkedData+'" width="150px" type="application/x-shockwave-flash"></embed>';
				$('#ad_box>div:eq('+(checkedVal-1)+')').html($('#ad_box>div:eq('+(checkedVal-1)+')').html()+typeHTML);
				break;

				case "3":
				$('#ad_box>div:eq('+(checkedVal-1)+') input:text[name="text"]').val(checkedData);
				break;
			}
			showType(checkedVal-1);
		}

		//如果无数据
		else
		{
			showType(0);
		}
		}

//表单回显
defaultShowType();
</script>
</html> 